package com.example.zwh.computershop.my_shopp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zwh.computershop.BottomAnimDialog;
import com.example.zwh.computershop.Myapp;
import com.example.zwh.computershop.R;

public class UserInfoActivity extends AppCompatActivity implements View.OnClickListener, BottomAnimDialog.OnCenterItemClickListener{
    Toolbar toolbar;
    private LinearLayout photo, name, sex, email;
    private TextView email_dis;
    private Myapp myapp;
    private TextView sex_alter, name_alter;

    BottomAnimDialog bottomAnimDialog_photo, bottomAnimDialog_sex, bottomAnimDialog_name;

    @Override
    public void OnCenterItemClick(BottomAnimDialog dialog, View view) {
        switch (view.getId()) {
            case R.id.taking_photo:
                Toast.makeText(this, "拍照", Toast.LENGTH_SHORT).show();
                break;
            case R.id.choose_photo:
                Toast.makeText(this, "从相册中选择", Toast.LENGTH_SHORT).show();
                break;
            case R.id.photo_cancel:
                Toast.makeText(this, "取消", Toast.LENGTH_SHORT).show();
                break;
            case R.id.male:
                Toast.makeText(this, "男", Toast.LENGTH_SHORT).show();
                break;
            case R.id.female:
                Toast.makeText(this, "女", Toast.LENGTH_SHORT).show();
                break;
            case R.id.sex_cancel:
                Toast.makeText(this, "取消性别选择", Toast.LENGTH_SHORT).show();
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_info);
       // showContentView();
        initView();
        initEvent();
        initData();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.main_photo:
                bottomAnimDialog_photo = new BottomAnimDialog(this, R.layout.activity_photo_dialog,
                        new int[]{R.id.taking_photo, R.id.choose_photo, R.id.photo_cancel});
                bottomAnimDialog_photo.setOnCenterItemClickListener(this);
                bottomAnimDialog_photo.show();
                break;
            case R.id.user_email:
                Toast.makeText(UserInfoActivity.this,"亲，邮箱不能修改哦",Toast.LENGTH_SHORT).show();
                break;
            case R.id.sex:
                bottomAnimDialog_sex = new BottomAnimDialog(this, R.layout.dialog_sex,
                        new int[]{R.id.male, R.id.female, R.id.sex_cancel});
                bottomAnimDialog_sex.setOnCenterItemClickListener(this);
                bottomAnimDialog_sex.show();
                break;
            case R.id.name:
                Intent intent = new Intent(this, ModifyInfoActivity.class);
                startActivity(intent);
                break;
            default:
                break;
        }
    }

    void initView() {
        email_dis = findViewById(R.id.email_dis);
        myapp = (Myapp) getApplication();

        photo = findViewById(R.id.main_photo);
        name = findViewById(R.id.name);
        sex = findViewById(R.id.sex);
        email = findViewById(R.id.user_email);
        sex_alter = findViewById(R.id.sex_alter);
        name_alter = findViewById(R.id.name_alter);

        toolbar = findViewById(R.id.info_toolBar);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.drawable.back);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    void initEvent() {
        photo.setOnClickListener(this);
        name.setOnClickListener(this);
        sex.setOnClickListener(this);
        email.setOnClickListener(this);
    }

    void initData() {
        email_dis.setText(myapp.getUser().getEmail());
        name_alter.setText(myapp.getUser().getUsername());
        if (myapp.getUser().getRole() == 1) {
            sex_alter.setText("男");
        }else {
            sex_alter.setText("女");
        }
    }
}
